home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / regrtest.py < prev    next >
Text File  |  2005-11-19  |  29KB  |  1,006 lines

  1. #! /usr/bin/env python
  2.  
  3. """Regression test.
  4.  
  5. This will find all modules whose name is "test_*" in the test
  6. directory, and run them.  Various command line options provide
  7. additional facilities.
  8.  
  9. Command line options:
  10.  
  11. -v: verbose   -- run tests in verbose mode with output to stdout
  12. -q: quiet     -- don't print anything except if a test fails
  13. -g: generate  -- write the output file for a test instead of comparing it
  14. -x: exclude   -- arguments are tests to *exclude*
  15. -s: single    -- run only a single test (see below)
  16. -r: random    -- randomize test execution order
  17. -f: fromfile  -- read names of tests to run from a file (see below)
  18. -l: findleaks -- if GC is available detect tests that leak memory
  19. -u: use       -- specify which special resource intensive tests to run
  20. -h: help      -- print this text and exit
  21. -t: threshold -- call gc.set_threshold(N)
  22.  
  23. If non-option arguments are present, they are names for tests to run,
  24. unless -x is given, in which case they are names for tests not to run.
  25. If no test names are given, all tests are run.
  26.  
  27. -v is incompatible with -g and does not compare test output files.
  28.  
  29. -s means to run only a single test and exit.  This is useful when
  30. doing memory analysis on the Python interpreter (which tend to consume
  31. too many resources to run the full regression test non-stop).  The
  32. file /tmp/pynexttest is read to find the next test to run.  If this
  33. file is missing, the first test_*.py file in testdir or on the command
  34. line is used.  (actually tempfile.gettempdir() is used instead of
  35. /tmp).
  36.  
  37. -f reads the names of tests from the file given as f's argument, one
  38. or more test names per line.  Whitespace is ignored.  Blank lines and
  39. lines beginning with '#' are ignored.  This is especially useful for
  40. whittling down failures involving interactions among tests.
  41.  
  42. -u is used to specify which special resource intensive tests to run,
  43. such as those requiring large file support or network connectivity.
  44. The argument is a comma-separated list of words indicating the
  45. resources to test.  Currently only the following are defined:
  46.  
  47.     all -       Enable all special resources.
  48.  
  49.     audio -     Tests that use the audio device.  (There are known
  50.                 cases of broken audio drivers that can crash Python or
  51.                 even the Linux kernel.)
  52.  
  53.     curses -    Tests that use curses and will modify the terminal's
  54.                 state and output modes.
  55.  
  56.     largefile - It is okay to run some test that may create huge
  57.                 files.  These tests can take a long time and may
  58.                 consume >2GB of disk space temporarily.
  59.  
  60.     network -   It is okay to run tests that use external network
  61.                 resource, e.g. testing SSL support for sockets.
  62.  
  63.     bsddb -     It is okay to run the bsddb testsuite, which takes
  64.                 a long time to complete.
  65.  
  66. To enable all resources except one, use '-uall,-<resource>'.  For
  67. example, to run all the tests except for the bsddb tests, give the
  68. option '-uall,-bsddb'.
  69. """
  70.  
  71. import sys
  72. import os
  73. import getopt
  74. import traceback
  75. import random
  76. import cStringIO
  77. import warnings
  78. from sets import Set
  79.  
  80. # I see no other way to suppress these warnings;
  81. # putting them in test_grammar.py has no effect:
  82. warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
  83.                         ".*test.test_grammar$")
  84. if sys.maxint > 0x7fffffff:
  85.     # Also suppress them in <string>, because for 64-bit platforms,
  86.     # that's where test_grammar.py hides them.
  87.     warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
  88.                             "<string>")
  89.  
  90. # MacOSX (a.k.a. Darwin) has a default stack size that is too small
  91. # for deeply recursive regular expressions.  We see this as crashes in
  92. # the Python test suite when running test_re.py and test_sre.py.  The
  93. # fix is to set the stack limit to 2048.
  94. # This approach may also be useful for other Unixy platforms that
  95. # suffer from small default stack limits.
  96. if sys.platform == 'darwin':
  97.     try:
  98.         import resource
  99.     except ImportError:
  100.         pass
  101.     else:
  102.         soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
  103.         newsoft = min(hard, max(soft, 1024*2048))
  104.         resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
  105.  
  106. from test import test_support
  107.  
  108. RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb')
  109.  
  110.  
  111. def usage(code, msg=''):
  112.     print __doc__
  113.     if msg: print msg
  114.     sys.exit(code)
  115.  
  116.  
  117. def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
  118.          exclude=0, single=0, randomize=0, fromfile=None, findleaks=0,
  119.          use_resources=None):
  120.     """Execute a test suite.
  121.  
  122.     This also parses command-line options and modifies its behavior
  123.     accordingly.
  124.  
  125.     tests -- a list of strings containing test names (optional)
  126.     testdir -- the directory in which to look for tests (optional)
  127.  
  128.     Users other than the Python test suite will certainly want to
  129.     specify testdir; if it's omitted, the directory containing the
  130.     Python test suite is searched for.
  131.  
  132.     If the tests argument is omitted, the tests listed on the
  133.     command-line will be used.  If that's empty, too, then all *.py
  134.     files beginning with test_ will be used.
  135.  
  136.     The other default arguments (verbose, quiet, generate, exclude,
  137.     single, randomize, findleaks, and use_resources) allow programmers
  138.     calling main() directly to set the values that would normally be
  139.     set by flags on the command line.
  140.  
  141.     """
  142.  
  143.     test_support.record_original_stdout(sys.stdout)
  144.     try:
  145.         opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:',
  146.                                    ['help', 'verbose', 'quiet', 'generate',
  147.                                     'exclude', 'single', 'random', 'fromfile',
  148.                                     'findleaks', 'use=', 'threshold='])
  149.     except getopt.error, msg:
  150.         usage(2, msg)
  151.  
  152.     # Defaults
  153.     if use_resources is None:
  154.         use_resources = []
  155.     for o, a in opts:
  156.         if o in ('-h', '--help'):
  157.             usage(0)
  158.         elif o in ('-v', '--verbose'):
  159.             verbose += 1
  160.         elif o in ('-q', '--quiet'):
  161.             quiet = 1;
  162.             verbose = 0
  163.         elif o in ('-g', '--generate'):
  164.             generate = 1
  165.         elif o in ('-x', '--exclude'):
  166.             exclude = 1
  167.         elif o in ('-s', '--single'):
  168.             single = 1
  169.         elif o in ('-r', '--randomize'):
  170.             randomize = 1
  171.         elif o in ('-f', '--fromfile'):
  172.             fromfile = a
  173.         elif o in ('-l', '--findleaks'):
  174.             findleaks = 1
  175.         elif o in ('-t', '--threshold'):
  176.             import gc
  177.             gc.set_threshold(int(a))
  178.         elif o in ('-u', '--use'):
  179.             u = [x.lower() for x in a.split(',')]
  180.             for r in u:
  181.                 if r == 'all':
  182.                     use_resources[:] = RESOURCE_NAMES
  183.                     continue
  184.                 remove = False
  185.                 if r[0] == '-':
  186.                     remove = True
  187.                     r = r[1:]
  188.                 if r not in RESOURCE_NAMES:
  189.                     usage(1, 'Invalid -u/--use option: ' + a)
  190.                 if remove:
  191.                     if r in use_resources:
  192.                         use_resources.remove(r)
  193.                 elif r not in use_resources:
  194.                     use_resources.append(r)
  195.     if generate and verbose:
  196.         usage(2, "-g and -v don't go together!")
  197.     if single and fromfile:
  198.         usage(2, "-s and -f don't go together!")
  199.  
  200.     good = []
  201.     bad = []
  202.     skipped = []
  203.     resource_denieds = []
  204.  
  205.     if findleaks:
  206.         try:
  207.             import gc
  208.         except ImportError:
  209.             print 'No GC available, disabling findleaks.'
  210.             findleaks = 0
  211.         else:
  212.             # Uncomment the line below to report garbage that is not
  213.             # freeable by reference counting alone.  By default only
  214.             # garbage that is not collectable by the GC is reported.
  215.             #gc.set_debug(gc.DEBUG_SAVEALL)
  216.             found_garbage = []
  217.  
  218.     if single:
  219.         from tempfile import gettempdir
  220.         filename = os.path.join(gettempdir(), 'pynexttest')
  221.         try:
  222.             fp = open(filename, 'r')
  223.             next = fp.read().strip()
  224.             tests = [next]
  225.             fp.close()
  226.         except IOError:
  227.             pass
  228.  
  229.     if fromfile:
  230.         tests = []
  231.         fp = open(fromfile)
  232.         for line in fp:
  233.             guts = line.split() # assuming no test has whitespace in its name
  234.             if guts and not guts[0].startswith('#'):
  235.                 tests.extend(guts)
  236.         fp.close()
  237.  
  238.     # Strip .py extensions.
  239.     if args:
  240.         args = map(removepy, args)
  241.     if tests:
  242.         tests = map(removepy, tests)
  243.  
  244.     stdtests = STDTESTS[:]
  245.     nottests = NOTTESTS[:]
  246.     if exclude:
  247.         for arg in args:
  248.             if arg in stdtests:
  249.                 stdtests.remove(arg)
  250.         nottests[:0] = args
  251.         args = []
  252.     tests = tests or args or findtests(testdir, stdtests, nottests)
  253.     if single:
  254.         tests = tests[:1]
  255.     if randomize:
  256.         random.shuffle(tests)
  257.     test_support.verbose = verbose      # Tell tests to be moderately quiet
  258.     test_support.use_resources = use_resources
  259.     save_modules = sys.modules.keys()
  260.     for test in tests:
  261.         if not quiet:
  262.             print test
  263.             sys.stdout.flush()
  264.         ok = runtest(test, generate, verbose, quiet, testdir)
  265.         if ok > 0:
  266.             good.append(test)
  267.         elif ok == 0:
  268.             bad.append(test)
  269.         else:
  270.             skipped.append(test)
  271.             if ok == -2:
  272.                 resource_denieds.append(test)
  273.         if findleaks:
  274.             gc.collect()
  275.             if gc.garbage:
  276.                 print "Warning: test created", len(gc.garbage),
  277.                 print "uncollectable object(s)."
  278.                 # move the uncollectable objects somewhere so we don't see
  279.                 # them again
  280.                 found_garbage.extend(gc.garbage)
  281.                 del gc.garbage[:]
  282.         # Unload the newly imported modules (best effort finalization)
  283.         for module in sys.modules.keys():
  284.             if module not in save_modules and module.startswith("test."):
  285.                 test_support.unload(module)
  286.  
  287.     # The lists won't be sorted if running with -r
  288.     good.sort()
  289.     bad.sort()
  290.     skipped.sort()
  291.  
  292.     if good and not quiet:
  293.         if not bad and not skipped and len(good) > 1:
  294.             print "All",
  295.         print count(len(good), "test"), "OK."
  296.         if verbose:
  297.             print "CAUTION:  stdout isn't compared in verbose mode:"
  298.             print "a test that passes in verbose mode may fail without it."
  299.     if bad:
  300.         print count(len(bad), "test"), "failed:"
  301.         printlist(bad)
  302.     if skipped and not quiet:
  303.         print count(len(skipped), "test"), "skipped:"
  304.         printlist(skipped)
  305.  
  306.         e = _ExpectedSkips()
  307.         plat = sys.platform
  308.         if e.isvalid():
  309.             surprise = Set(skipped) - e.getexpected() - Set(resource_denieds)
  310.             if surprise:
  311.                 print count(len(surprise), "skip"), \
  312.                       "unexpected on", plat + ":"
  313.                 printlist(surprise)
  314.             else:
  315.                 print "Those skips are all expected on", plat + "."
  316.         else:
  317.             print "Ask someone to teach regrtest.py about which tests are"
  318.             print "expected to get skipped on", plat + "."
  319.  
  320.     if single:
  321.         alltests = findtests(testdir, stdtests, nottests)
  322.         for i in range(len(alltests)):
  323.             if tests[0] == alltests[i]:
  324.                 if i == len(alltests) - 1:
  325.                     os.unlink(filename)
  326.                 else:
  327.                     fp = open(filename, 'w')
  328.                     fp.write(alltests[i+1] + '\n')
  329.                     fp.close()
  330.                 break
  331.         else:
  332.             os.unlink(filename)
  333.  
  334.     sys.exit(len(bad) > 0)
  335.  
  336.  
  337. STDTESTS = [
  338.     'test_grammar',
  339.     'test_opcodes',
  340.     'test_operations',
  341.     'test_builtin',
  342.     'test_exceptions',
  343.     'test_types',
  344.    ]
  345.  
  346. NOTTESTS = [
  347.     'test_support',
  348.     'test_future1',
  349.     'test_future2',
  350.     'test_future3',
  351.     ]
  352.  
  353. def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
  354.     """Return a list of all applicable test modules."""
  355.     if not testdir: testdir = findtestdir()
  356.     names = os.listdir(testdir)
  357.     tests = []
  358.     for name in names:
  359.         if name[:5] == "test_" and name[-3:] == os.extsep+"py":
  360.             modname = name[:-3]
  361.             if modname not in stdtests and modname not in nottests:
  362.                 tests.append(modname)
  363.     tests.sort()
  364.     return stdtests + tests
  365.  
  366. def runtest(test, generate, verbose, quiet, testdir = None):
  367.     """Run a single test.
  368.     test -- the name of the test
  369.     generate -- if true, generate output, instead of running the test
  370.     and comparing it to a previously created output file
  371.     verbose -- if true, print more messages
  372.     quiet -- if true, don't print 'skipped' messages (probably redundant)
  373.     testdir -- test directory
  374.     """
  375.     test_support.unload(test)
  376.     if not testdir: testdir = findtestdir()
  377.     outputdir = os.path.join(testdir, "output")
  378.     outputfile = os.path.join(outputdir, test)
  379.     if verbose:
  380.         cfp = None
  381.     else:
  382.         cfp = cStringIO.StringIO()
  383.     try:
  384.         save_stdout = sys.stdout
  385.         try:
  386.             if cfp:
  387.                 sys.stdout = cfp
  388.                 print test              # Output file starts with test name
  389.             if test.startswith('test.'):
  390.                 abstest = test
  391.             else:
  392.                 # Always import it from the test package
  393.                 abstest = 'test.' + test
  394.             the_package = __import__(abstest, globals(), locals(), [])
  395.             the_module = getattr(the_package, test)
  396.             # Most tests run to completion simply as a side-effect of
  397.             # being imported.  For the benefit of tests that can't run
  398.             # that way (like test_threaded_import), explicitly invoke
  399.             # their test_main() function (if it exists).
  400.             indirect_test = getattr(the_module, "test_main", None)
  401.             if indirect_test is not None:
  402.                 indirect_test()
  403.         finally:
  404.             sys.stdout = save_stdout
  405.     except test_support.ResourceDenied, msg:
  406.         if not quiet:
  407.             print test, "skipped --", msg
  408.             sys.stdout.flush()
  409.         return -2
  410.     except (ImportError, test_support.TestSkipped), msg:
  411.         if not quiet:
  412.             print test, "skipped --", msg
  413.             sys.stdout.flush()
  414.         return -1
  415.     except KeyboardInterrupt:
  416.         raise
  417.     except test_support.TestFailed, msg:
  418.         print "test", test, "failed --", msg
  419.         sys.stdout.flush()
  420.         return 0
  421.     except:
  422.         type, value = sys.exc_info()[:2]
  423.         print "test", test, "crashed --", str(type) + ":", value
  424.         sys.stdout.flush()
  425.         if verbose:
  426.             traceback.print_exc(file=sys.stdout)
  427.             sys.stdout.flush()
  428.         return 0
  429.     else:
  430.         if not cfp:
  431.             return 1
  432.         output = cfp.getvalue()
  433.         if generate:
  434.             if output == test + "\n":
  435.                 if os.path.exists(outputfile):
  436.                     # Write it since it already exists (and the contents
  437.                     # may have changed), but let the user know it isn't
  438.                     # needed:
  439.                     print "output file", outputfile, \
  440.                           "is no longer needed; consider removing it"
  441.                 else:
  442.                     # We don't need it, so don't create it.
  443.                     return 1
  444.             fp = open(outputfile, "w")
  445.             fp.write(output)
  446.             fp.close()
  447.             return 1
  448.         if os.path.exists(outputfile):
  449.             fp = open(outputfile, "r")
  450.             expected = fp.read()
  451.             fp.close()
  452.         else:
  453.             expected = test + "\n"
  454.         if output == expected:
  455.             return 1
  456.         print "test", test, "produced unexpected output:"
  457.         sys.stdout.flush()
  458.         reportdiff(expected, output)
  459.         sys.stdout.flush()
  460.         return 0
  461.  
  462. def reportdiff(expected, output):
  463.     import difflib
  464.     print "*" * 70
  465.     a = expected.splitlines(1)
  466.     b = output.splitlines(1)
  467.     sm = difflib.SequenceMatcher(a=a, b=b)
  468.     tuples = sm.get_opcodes()
  469.  
  470.     def pair(x0, x1):
  471.         # x0:x1 are 0-based slice indices; convert to 1-based line indices.
  472.         x0 += 1
  473.         if x0 >= x1:
  474.             return "line " + str(x0)
  475.         else:
  476.             return "lines %d-%d" % (x0, x1)
  477.  
  478.     for op, a0, a1, b0, b1 in tuples:
  479.         if op == 'equal':
  480.             pass
  481.  
  482.         elif op == 'delete':
  483.             print "***", pair(a0, a1), "of expected output missing:"
  484.             for line in a[a0:a1]:
  485.                 print "-", line,
  486.  
  487.         elif op == 'replace':
  488.             print "*** mismatch between", pair(a0, a1), "of expected", \
  489.                   "output and", pair(b0, b1), "of actual output:"
  490.             for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
  491.                 print line,
  492.  
  493.         elif op == 'insert':
  494.             print "***", pair(b0, b1), "of actual output doesn't appear", \
  495.                   "in expected output after line", str(a1)+":"
  496.             for line in b[b0:b1]:
  497.                 print "+", line,
  498.  
  499.         else:
  500.             print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
  501.  
  502.     print "*" * 70
  503.  
  504. def findtestdir():
  505.     if __name__ == '__main__':
  506.         file = sys.argv[0]
  507.     else:
  508.         file = __file__
  509.     testdir = os.path.dirname(file) or os.curdir
  510.     return testdir
  511.  
  512. def removepy(name):
  513.     if name.endswith(os.extsep + "py"):
  514.         name = name[:-3]
  515.     return name
  516.  
  517. def count(n, word):
  518.     if n == 1:
  519.         return "%d %s" % (n, word)
  520.     else:
  521.         return "%d %ss" % (n, word)
  522.  
  523. def printlist(x, width=70, indent=4):
  524.     """Print the elements of iterable x to stdout.
  525.  
  526.     Optional arg width (default 70) is the maximum line length.
  527.     Optional arg indent (default 4) is the number of blanks with which to
  528.     begin each line.
  529.     """
  530.  
  531.     from textwrap import fill
  532.     blanks = ' ' * indent
  533.     print fill(' '.join(map(str, x)), width,
  534.                initial_indent=blanks, subsequent_indent=blanks)
  535.  
  536. # Map sys.platform to a string containing the basenames of tests
  537. # expected to be skipped on that platform.
  538. #
  539. # Special cases:
  540. #     test_pep277
  541. #         The _ExpectedSkips constructor adds this to the set of expected
  542. #         skips if not os.path.supports_unicode_filenames.
  543. #     test_normalization
  544. #         Whether a skip is expected here depends on whether a large test
  545. #         input file has been downloaded.  test_normalization.skip_expected
  546. #         controls that.
  547. #     test_socket_ssl
  548. #         Controlled by test_socket_ssl.skip_expected.  Requires the network
  549. #         resource, and a socket module with ssl support.
  550. #     test_timeout
  551. #         Controlled by test_timeout.skip_expected.  Requires the network
  552. #         resource and a socket module.
  553.  
  554. _expectations = {
  555.     'win32':
  556.         """
  557.         test_al
  558.         test_bsddb185
  559.         test_bsddb3
  560.         test_cd
  561.         test_cl
  562.         test_commands
  563.         test_crypt
  564.         test_curses
  565.         test_dbm
  566.         test_dl
  567.         test_email_codecs
  568.         test_fcntl
  569.         test_fork1
  570.         test_gdbm
  571.         test_gl
  572.         test_grp
  573.         test_imgfile
  574.         test_ioctl
  575.         test_largefile
  576.         test_linuxaudiodev
  577.         test_mhlib
  578.         test_mpz
  579.         test_nis
  580.         test_openpty
  581.         test_ossaudiodev
  582.         test_poll
  583.         test_posix
  584.         test_pty
  585.         test_pwd
  586.         test_resource
  587.         test_signal
  588.         test_sunaudiodev
  589.         test_timing
  590.         """,
  591.     'linux2':
  592.         """
  593.         test_al
  594.         test_bsddb185
  595.         test_cd
  596.         test_cl
  597.         test_curses
  598.         test_dl
  599.         test_email_codecs
  600.         test_gl
  601.         test_imgfile
  602.         test_largefile
  603.         test_linuxaudiodev
  604.         test_nis
  605.         test_ntpath
  606.         test_ossaudiodev
  607.         test_sunaudiodev
  608.         """,
  609.    'mac':
  610.         """
  611.         test_al
  612.         test_atexit
  613.         test_bsddb
  614.         test_bsddb185
  615.         test_bsddb3
  616.         test_bz2
  617.         test_cd
  618.         test_cl
  619.         test_commands
  620.         test_crypt
  621.         test_curses
  622.         test_dbm
  623.         test_dl
  624.         test_email_codecs
  625.         test_fcntl
  626.         test_fork1
  627.         test_gl
  628.         test_grp
  629.         test_ioctl
  630.         test_imgfile
  631.         test_largefile
  632.         test_linuxaudiodev
  633.         test_locale
  634.         test_mmap
  635.         test_mpz
  636.         test_nis
  637.         test_ntpath
  638.         test_openpty
  639.         test_ossaudiodev
  640.         test_poll
  641.         test_popen
  642.         test_popen2
  643.         test_posix
  644.         test_pty
  645.         test_pwd
  646.         test_resource
  647.         test_signal
  648.         test_sunaudiodev
  649.         test_sundry
  650.         test_tarfile
  651.         test_timing
  652.         """,
  653.     'unixware7':
  654.         """
  655.         test_al
  656.         test_bsddb
  657.         test_bsddb185
  658.         test_cd
  659.         test_cl
  660.         test_dl
  661.         test_gl
  662.         test_imgfile
  663.         test_largefile
  664.         test_linuxaudiodev
  665.         test_minidom
  666.         test_nis
  667.         test_ntpath
  668.         test_openpty
  669.         test_pyexpat
  670.         test_sax
  671.         test_sunaudiodev
  672.         test_sundry
  673.         """,
  674.     'openunix8':
  675.         """
  676.         test_al
  677.         test_bsddb
  678.         test_bsddb185
  679.         test_cd
  680.         test_cl
  681.         test_dl
  682.         test_gl
  683.         test_imgfile
  684.         test_largefile
  685.         test_linuxaudiodev
  686.         test_minidom
  687.         test_nis
  688.         test_ntpath
  689.         test_openpty
  690.         test_pyexpat
  691.         test_sax
  692.         test_sunaudiodev
  693.         test_sundry
  694.         """,
  695.     'sco_sv3':
  696.         """
  697.         test_al
  698.         test_asynchat
  699.         test_bsddb
  700.         test_bsddb185
  701.         test_cd
  702.         test_cl
  703.         test_dl
  704.         test_fork1
  705.         test_gettext
  706.         test_gl
  707.         test_imgfile
  708.         test_largefile
  709.         test_linuxaudiodev
  710.         test_locale
  711.         test_minidom
  712.         test_nis
  713.         test_ntpath
  714.         test_openpty
  715.         test_pyexpat
  716.         test_queue
  717.         test_sax
  718.         test_sunaudiodev
  719.         test_sundry
  720.         test_thread
  721.         test_threaded_import
  722.         test_threadedtempfile
  723.         test_threading
  724.         """,
  725.     'riscos':
  726.         """
  727.         test_al
  728.         test_asynchat
  729.         test_atexit
  730.         test_bsddb
  731.         test_bsddb185
  732.         test_bsddb3
  733.         test_cd
  734.         test_cl
  735.         test_commands
  736.         test_crypt
  737.         test_dbm
  738.         test_dl
  739.         test_fcntl
  740.         test_fork1
  741.         test_gdbm
  742.         test_gl
  743.         test_grp
  744.         test_imgfile
  745.         test_largefile
  746.         test_linuxaudiodev
  747.         test_locale
  748.         test_mmap
  749.         test_nis
  750.         test_ntpath
  751.         test_openpty
  752.         test_poll
  753.         test_popen2
  754.         test_pty
  755.         test_pwd
  756.         test_strop
  757.         test_sunaudiodev
  758.         test_sundry
  759.         test_thread
  760.         test_threaded_import
  761.         test_threadedtempfile
  762.         test_threading
  763.         test_timing
  764.         """,
  765.     'darwin':
  766.         """
  767.         test_al
  768.         test_bsddb
  769.         test_bsddb3
  770.         test_cd
  771.         test_cl
  772.         test_curses
  773.         test_dl
  774.         test_email_codecs
  775.         test_gdbm
  776.         test_gl
  777.         test_imgfile
  778.         test_largefile
  779.         test_linuxaudiodev
  780.         test_locale
  781.         test_minidom
  782.         test_mpz
  783.         test_nis
  784.         test_ntpath
  785.         test_ossaudiodev
  786.         test_poll
  787.         test_sunaudiodev
  788.         """,
  789.     'sunos5':
  790.         """
  791.         test_al
  792.         test_bsddb
  793.         test_bsddb185
  794.         test_cd
  795.         test_cl
  796.         test_curses
  797.         test_dbm
  798.         test_email_codecs
  799.         test_gdbm
  800.         test_gl
  801.         test_gzip
  802.         test_imgfile
  803.         test_linuxaudiodev
  804.         test_mpz
  805.         test_openpty
  806.         test_zipfile
  807.         test_zlib
  808.         """,
  809.     'hp-ux11':
  810.         """
  811.         test_al
  812.         test_bsddb
  813.         test_bsddb185
  814.         test_cd
  815.         test_cl
  816.         test_curses
  817.         test_dl
  818.         test_gdbm
  819.         test_gl
  820.         test_gzip
  821.         test_imgfile
  822.         test_largefile
  823.         test_linuxaudiodev
  824.         test_locale
  825.         test_minidom
  826.         test_nis
  827.         test_ntpath
  828.         test_openpty
  829.         test_pyexpat
  830.         test_sax
  831.         test_sunaudiodev
  832.         test_zipfile
  833.         test_zlib
  834.         """,
  835.     'atheos':
  836.         """
  837.         test_al
  838.         test_bsddb185
  839.         test_cd
  840.         test_cl
  841.         test_curses
  842.         test_dl
  843.         test_email_codecs
  844.         test_gdbm
  845.         test_gl
  846.         test_imgfile
  847.         test_largefile
  848.         test_linuxaudiodev
  849.         test_locale
  850.         test_mhlib
  851.         test_mmap
  852.         test_mpz
  853.         test_nis
  854.         test_poll
  855.         test_popen2
  856.         test_resource
  857.         test_sunaudiodev
  858.         """,
  859.     'cygwin':
  860.         """
  861.         test_al
  862.         test_bsddb185
  863.         test_bsddb3
  864.         test_cd
  865.         test_cl
  866.         test_curses
  867.         test_dbm
  868.         test_email_codecs
  869.         test_gl
  870.         test_imgfile
  871.         test_ioctl
  872.         test_largefile
  873.         test_linuxaudiodev
  874.         test_locale
  875.         test_mpz
  876.         test_nis
  877.         test_ossaudiodev
  878.         test_socketserver
  879.         test_sunaudiodev
  880.         """,
  881.     'os2emx':
  882.         """
  883.         test_al
  884.         test_audioop
  885.         test_bsddb185
  886.         test_bsddb3
  887.         test_cd
  888.         test_cl
  889.         test_commands
  890.         test_curses
  891.         test_dl
  892.         test_email_codecs
  893.         test_gl
  894.         test_imgfile
  895.         test_largefile
  896.         test_linuxaudiodev
  897.         test_mhlib
  898.         test_mmap
  899.         test_nis
  900.         test_openpty
  901.         test_ossaudiodev
  902.         test_pty
  903.         test_resource
  904.         test_signal
  905.         test_sunaudiodev
  906.         """,
  907.      'freebsd4':
  908.          """
  909.        test_aepack
  910.        test_al
  911.        test_bsddb
  912.        test_bsddb3
  913.        test_cd
  914.        test_cl
  915.        test_email_codecs
  916.        test_gl
  917.        test_imgfile
  918.        test_linuxaudiodev
  919.        test_locale
  920.        test_macfs
  921.        test_macostools
  922.        test_nis
  923.        test_normalization
  924.        test_ossaudiodev
  925.        test_pep277
  926.        test_plistlib
  927.        test_scriptpackages
  928.        test_socket_ssl
  929.        test_socketserver
  930.        test_sunaudiodev
  931.        test_timeout
  932.        test_unicode_file
  933.        test_urllibnet
  934.        test_winreg
  935.        test_winsound
  936.         """,
  937. }
  938.  
  939. class _ExpectedSkips:
  940.     def __init__(self):
  941.         import os.path
  942.         from test import test_normalization
  943.         from test import test_socket_ssl
  944.         from test import test_timeout
  945.  
  946.         self.valid = False
  947.         if sys.platform in _expectations:
  948.             s = _expectations[sys.platform]
  949.             self.expected = Set(s.split())
  950.  
  951.             if not os.path.supports_unicode_filenames:
  952.                 self.expected.add('test_pep277')
  953.  
  954.             if test_normalization.skip_expected:
  955.                 self.expected.add('test_normalization')
  956.  
  957.             if test_socket_ssl.skip_expected:
  958.                 self.expected.add('test_socket_ssl')
  959.  
  960.             if test_timeout.skip_expected:
  961.                 self.expected.add('test_timeout')
  962.  
  963.             if not sys.platform in ("mac", "darwin"):
  964.                 MAC_ONLY = ["test_macostools", "test_macfs", "test_aepack",
  965.                             "test_plistlib", "test_scriptpackages"]
  966.                 for skip in MAC_ONLY:
  967.                     self.expected.add(skip)
  968.  
  969.             if sys.platform != "win32":
  970.                 WIN_ONLY = ["test_unicode_file", "test_winreg",
  971.                             "test_winsound"]
  972.                 for skip in WIN_ONLY:
  973.                     self.expected.add(skip)
  974.  
  975.             self.valid = True
  976.  
  977.     def isvalid(self):
  978.         "Return true iff _ExpectedSkips knows about the current platform."
  979.         return self.valid
  980.  
  981.     def getexpected(self):
  982.         """Return set of test names we expect to skip on current platform.
  983.  
  984.         self.isvalid() must be true.
  985.         """
  986.  
  987.         assert self.isvalid()
  988.         return self.expected
  989.  
  990. if __name__ == '__main__':
  991.     # Remove regrtest.py's own directory from the module search path.  This
  992.     # prevents relative imports from working, and relative imports will screw
  993.     # up the testing framework.  E.g. if both test.test_support and
  994.     # test_support are imported, they will not contain the same globals, and
  995.     # much of the testing framework relies on the globals in the
  996.     # test.test_support module.
  997.     mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
  998.     i = pathlen = len(sys.path)
  999.     while i >= 0:
  1000.         i -= 1
  1001.         if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
  1002.             del sys.path[i]
  1003.     if len(sys.path) == pathlen:
  1004.         print 'Could not find %r in sys.path to remove it' % mydir
  1005.     main()
  1006.